package com.sgb.kjwl.view.ui.activity.self.pick;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivitySelfPickList3Binding;
import com.sgb.kjwl.view.ui.fragment.self.pick.SelfPickListFragment3;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;

import java.util.ArrayList;

/**
 * 2020-7-17
 * type1 我的集采
 * type2 我的加盟
 *
 * 已废弃
 */
public class SelfPickListActivity3 extends AppActivity {
    private ActivitySelfPickList3Binding binding;
    private FragPagerAdapter pagerAdapter1;
    private FragPagerAdapter pagerAdapter2;
    private ArrayList<Fragment> fragments1;
    private ArrayList<Fragment> fragments2;
    private String[] titles1 = {"全部", "集采中", "集采完成", "集采失败"};
    private String[] titles2 = {"全部", "集采中", "集采完成", "集采失败"};

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    public static void start(Context context, String type) {
        Intent intent = new Intent();
        intent.putExtra("type", type);
        intent.setClass(context, SelfPickListActivity3.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_self_pick_list3);
        binding.include.ivBack.setOnClickListener(this);
//        binding.ivBack.setVisibility(View.VISIBLE);
//        binding.ivBack.setOnClickListener(this);
//        binding.tab1View.setOnClickListener(this);
//        binding.tab2View.setOnClickListener(this);
//        binding.tab1View.setSelected(true);

        if (getIntent().getStringExtra("type").equals("1")) {
            binding.include.titleView.setText("我的集采");
            initTab1View();
        } else {
            binding.include.titleView.setText("我的加盟");
            initTab2View();
            changeTab2();
        }
    }

    @Override
    protected void init() {

    }

    private void initTab1View() {
        fragments1 = new ArrayList<>();
        fragments1.add(SelfPickListFragment3.newInstance("1", "0"));
        fragments1.add(SelfPickListFragment3.newInstance("1", "1"));
        fragments1.add(SelfPickListFragment3.newInstance("1", "2"));
        fragments1.add(SelfPickListFragment3.newInstance("1", "4"));
        pagerAdapter1 = new FragPagerAdapter(getSupportFragmentManager(), fragments1);
        binding.viewpager1.setAdapter(pagerAdapter1);
        binding.viewpager1.setOffscreenPageLimit(3);
        binding.tablayout1.setViewPager(binding.viewpager1, titles1);
    }

    private void initTab2View() {
        fragments2 = new ArrayList<>();
        fragments2.add(SelfPickListFragment3.newInstance("2", "0"));
        fragments2.add(SelfPickListFragment3.newInstance("2", "1"));
        fragments2.add(SelfPickListFragment3.newInstance("2", "2"));
        fragments2.add(SelfPickListFragment3.newInstance("2", "4"));
        pagerAdapter2 = new FragPagerAdapter(getSupportFragmentManager(), fragments2);
        binding.viewpager2.setAdapter(pagerAdapter2);
        binding.viewpager2.setOffscreenPageLimit(3);
        binding.tablayout2.setViewPager(binding.viewpager2, titles2);
    }

    public void changeTab(String type, String status, int size) {
        if (type.equals("1")) {
            if (status.equals("0")) {
                titles1[0] = "全部" + "(" + size + ")";
            } else if (status.equals("1")) {
                titles1[1] = "集采中" + "(" + size + ")";
            } else if (status.equals("2")) {
                titles1[2] = "集采完成" + "(" + size + ")";
            } else if (status.equals("4")) {
                titles1[3] = "集采失败" + "(" + size + ")";
            }
            binding.tablayout1.setViewPager(binding.viewpager1, titles1);
        } else {
            if (status.equals("0")) {
                titles2[0] = "全部" + "(" + size + ")";
            } else if (status.equals("1")) {
                titles2[1] = "集采中" + "(" + size + ")";
            } else if (status.equals("2")) {
                titles2[2] = "集采完成" + "(" + size + ")";
            } else if (status.equals("4")) {
                titles2[3] = "集采失败" + "(" + size + ")";
            }
            binding.tablayout2.setViewPager(binding.viewpager2, titles2);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
//            case R.id.tab1_view:
//                changeTab1();
//                break;
//            case R.id.tab2_view:
//                changeTab2();
//                break;
        }

    }

    private void changeTab1() {
//        binding.tab1View.setSelected(true);
//        binding.tab2View.setSelected(false);
//        binding.tab1Line.setVisibility(View.VISIBLE);
//        binding.tab2Line.setVisibility(View.GONE);
        binding.tab1Layout.setVisibility(View.VISIBLE);
        binding.tab2Layout.setVisibility(View.GONE);
    }

    private void changeTab2() {
//        binding.tab1View.setSelected(false);
//        binding.tab2View.setSelected(true);
//        binding.tab1Line.setVisibility(View.GONE);
//        binding.tab2Line.setVisibility(View.VISIBLE);
        binding.tab1Layout.setVisibility(View.GONE);
        binding.tab2Layout.setVisibility(View.VISIBLE);
    }

}
